﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using KMF.Common;
using KMF.DAL;
using KMF.WebUI.Areas.KMFadmin.Attributes;
using KMF.WebUI.Areas.KMFadmin.Models;
using System.Configuration;
using KMF.Utility;
using KMF.WebUI.Areas.KMFadmin.CustomHelpers;

namespace KMF.WebUI.Areas.KMFadmin.Controllers
{
    [AdminLoggedAuthorize]
    public class AdminOrderController : Controller
    {
        //
        // GET: /Order/

        public ActionResult Index(int page = 1)
        {
            var itemsPerPage = int.Parse(ConfigurationManager.AppSettings["DefaultItemsPerPage"]);
            var totalPage = 0;
            var model = OrderDb.GetAllOrderPaging(page, itemsPerPage, ref totalPage) ?? new List<OrderPagingDto>();
            ViewBag.ListOption = CommonHelpers.SelectOptionFilterOrder();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            return View(model);
        }

        public ActionResult Detail(string id)
        {
            var model = OrderDb.GetById(id) ?? new OrderDto();
            ViewBag.OrderDetail = OrderDb.GetDetailByOrderId(id) ?? new List<OrderDetailProductDto>();
            return View(model);
        }

        public ActionResult Filter(string StartDate, string EndDate, int page = 1)
        {
            //lay 
            var itemsPerPage = 1000;
            var totalPage = 0;
            var model = OrderDb.GetAllOrderFilterPaging(page, itemsPerPage, ref totalPage, Convert.ToDateTime(StartDate), Convert.ToDateTime(EndDate).AddDays(1)) ?? new List<OrderPagingDto>();
            ViewBag.StartDate = StartDate;
            ViewBag.EndDate = EndDate;
            ViewBag.ListOption = CommonHelpers.SelectOptionFilterOrder();
            return View(model);
        }
    }
}
